
# -*-coding:utf-8 -*-

import numpy as np

from scipy import interpolate

import pylab as pl

x = np.linspace(0, 10, 11)

# x=[  0.   1.   2.   3.   4.   5.   6.   7.   8.   9.  10.]

y = 1 / (1+25*x*x)

xnew = np.linspace(0, 10, 101)

pl.plot(x, y, "ro")

# for kind in ["nearest", "zero", "slinear", "quadratic", "cubic"]:  # 插值方式
for kind in ['nearest']:
    # "nearest","zero"为阶梯插值

    # slinear 线性插值

    # "quadratic","cubic" 为2阶、3阶B样条曲线插值

    f = interpolate.interp1d(x, y, kind=kind)

    # ‘slinear’, ‘quadratic’ and ‘cubic’ refer to a spline interpolation of first, second or third order)

    ynew = f(xnew)

    pl.plot(xnew, ynew, label=str(kind))  # label用来显示图例

pl.legend(loc="best")  # 显示图例的位置

pl.show()
